import math
import 龙头xy as getXy

from scipy.optimize import fsolve

a = 0.55 / (math.pi * 2)


def getNextJiao(x0, y0, len, cjiao):
    p = 0.01
    flen = len
    fx = x0
    fy = y0

    def qaulityJiao(jiao):
        x1 = jiao * a * math.cos(jiao)
        y1 = jiao * a * math.sin(jiao)
        q1 = (y1 - fy) ** 2 + (x1 - fx) ** 2 - flen ** 2
        return q1

    nextJiao = fsolve(qaulityJiao, cjiao + p)
    while nextJiao[0] < cjiao or math.fabs(a * cjiao - a * nextJiao[0]) > 0.55 / 2:
        p = p + 0.1
        nextJiao = fsolve(qaulityJiao, cjiao + p)
    return nextJiao


def printArray(arr):
    for i in arr:
        print(format(i, '.6f'), end='\t')
    print()


t = [0, 60, 120, 180, 240, 300]


def isExist(i):
    for m in t:
        if m == i:
            return True
    return False


x = [k for k in range(301)]
y = [k for k in range(301)]
jiao = [k for k in range(301)]
v = [k for k in range(301)]
a = [151, 201, 223]
for i in range(224):
    if i == 0:
        for j in range(301):
            x[j], y[j], jiao[j] = getXy.xyByTime(j)
            v[j] = 1
    elif i == 1:
        for j in range(301):
            nextJiao = getNextJiao(x[j], y[j], 2.86, cjiao=jiao[j])
            x[j] = nextJiao[0] * a * math.cos(nextJiao[0])
            y[j] = nextJiao[0] * a * math.sin(nextJiao[0])
            r0 = jiao[j] * a
            r1 = nextJiao[0] * a
            v[j] = (v[j] * r1) / r0
            jiao[j] = nextJiao[0]

    else:
        for j in range(301):
            nextJiao = getNextJiao(x[j], y[j], 1.65, cjiao=jiao[j])
            x[j] = nextJiao[0] * a * math.cos(nextJiao[0])
            y[j] = nextJiao[0] * a * math.sin(nextJiao[0])
            r0 = jiao[j] * a
            r1 = nextJiao[0] * a
            v[j] = (v[j] * r1) / r0
            jiao[j] = nextJiao[0]

    if isExist(i):
        for k in range(6):
            print(x[t[k]], end='\t')
        print()
